// pages/myAddCode/myAddCode.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabBar: [
      {
        url: "jifenbut@2x.png",
        name: '分销积分',
        content: "",
        bindTab: "getCode"
      },
      {
        url: "xiaxianyh@2x.png",
        name: '下线用户',
        content: "",
        bindTab: "offline"
      },
      {
        url: "erweima@2x.png",
        name: '推广二维码',
        content: "",
        bindTab: "myCode"
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    getDistribution(that)
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          userInfo: wx.getStorageSync("userInfo"),
          userTypeName: wx.getStorageSync("userTypeName"),
          userDetail: wx.getStorageSync("remoteUserDetail")
        });
      }
    });
  },

  myCode: function () {
    wx.navigateTo({
      url: '../../pages/myCode/myCode',
    })
  },
  offline: function () {
    wx.navigateTo({
      url: '../../pages/member/member',
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

function getDistribution(that) {
  console.log(wx.getStorageSync("userid"))
  wx.request({
    url: app.globalData.allUrl + "/utilAction/getDistribution",
    data: {
      userID: wx.getStorageSync("userid")
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      console.log(res.data);
      that.data.tabBar[0].content = res.data.fxBrokerage;
      that.data.tabBar[1].content = res.data.downline;
      that.setData({
        userDistribution: res.data,
        tabBar: that.data.tabBar
      })
    }
  })
}